package com.bw.zg3.notice.Car1

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bw.base.entity.Car1EntityREsultItem
import com.bw.zg3.R
import com.bw.zg3.databinding.Car1Binding


class H1Apter :PagingDataAdapter<Car1EntityREsultItem,H1Apter.H1ViewHolder>(H1) {
    private var mOnItemClickListener: OnItemClickListener? = null
    private var mOnItemLongClickListener: OnItemLongClickListener? = null
    companion object{
        val H1=object :ItemCallback<Car1EntityREsultItem>(){
            override fun areItemsTheSame(
                oldItem: Car1EntityREsultItem,
                newItem: Car1EntityREsultItem,
            ): Boolean {
                return oldItem==newItem
            }

            override fun areContentsTheSame(
                oldItem: Car1EntityREsultItem,
                newItem: Car1EntityREsultItem,
            ): Boolean {
               return oldItem.id==newItem.id
            }

        }
    }
    class H1ViewHolder(view: View):ViewHolder(view){
        val binding =DataBindingUtil.bind<Car1Binding>(view)
    }

    override fun onBindViewHolder(holder: H1Apter.H1ViewHolder, position: Int) {
        holder.binding?.ca=getItem(position)
        val item = getItem(position)

        holder.binding?.zt?.apply {
            when(item?.spaceStatus){
                "空闲"->{
                    setBackgroundResource(R.drawable.greent)
                    setTextColor(holder.itemView.context.resources.getColor(R.color.green))
                }
                "已占用"->{
                    setBackgroundResource(R.drawable.bule)
                    setTextColor(holder.itemView.context.resources.getColor(R.color.blue))
                }
                "维修中"->{
                    setBackgroundResource(R.drawable.yellow)
                    setTextColor(holder.itemView.context.resources.getColor(R.color.ora))
                }
            }
        }







        holder.itemView.setOnClickListener {
            this.mOnItemClickListener?.onItemClick(position,item!!)
        }
        holder.itemView.setOnClickListener {
            this.mOnItemLongClickListener?.onItemLongClick(item!!)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): H1Apter.H1ViewHolder {
        val inflate = LayoutInflater.from(parent.context).inflate(R.layout.car1, parent, false)
        return H1ViewHolder(inflate)
    }
     fun setOnItemClickListener(listener: OnItemClickListener?) {
        this.mOnItemClickListener = listener
    }

     fun setOnItemLongClickListener(listener: OnItemLongClickListener?) {
        this.mOnItemLongClickListener = listener
    }
    interface OnItemClickListener {

        fun onItemClick(position: Int,item: Car1EntityREsultItem)
    }
    interface OnItemLongClickListener {

        fun onItemLongClick(item: Car1EntityREsultItem): Boolean
    }
}